package com.Z型转换;

public class Again {

	public String convert(String s, int nRows) {
        char c[] = new char[s.length()];
        int ci = 0;
        int index=0;
        for(int i=1;i<=nRows;i++){
            index=i-1;
            if(i==1||i==nRows){
                while(index<s.length()&&ci<s.length()){
                    c[ci++] = s.charAt(index);
                    index = index+2*(nRows-1);
                }
            }
            else{
                while(index<s.length()&&ci<s.length()){
                    c[ci++] = s.charAt(index);
                    if(index+2*(nRows-i)<s.length()&&ci<s.length()){
                        c[ci++] = s.charAt(index+2*(nRows-i));
                        index = index+2*(nRows-1);
                    }
                    else{
                        break;
                    }
            }
        }
            
      }
        String res = new String(c);
            return res;
    }

}
